<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户性别</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sex" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户城市</label>
                            <div class="layui-input-inline">
                                <input type="text" name="city" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户职业</label>
                            <div class="layui-input-inline">
                                <input type="text" name="classify" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="employeeTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/system/queryAllWorkOrderEmployeeUseDto',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                {type: "checkbox", width: 50},
                {field: 'workOrderId', width: 80, title: 'ID', sort: true},
                {field: 'waybillNo', width: 120, title: '面单号'},
                    {field: 'employeeId', width: 120, title: '客户id'},
                {field: 'cutomerName', width: 120, title: '客户名称', sort: true},
                {field: 'customerTel', width: 200, title: '客户电话'},
                {field: 'workOrderBeginTime', title: '工单发起时间', minWidth: 150},
                {field: 'questionType', width: 120, title: '问题类型', sort: true},
                    {width:100, title: '工单状态', templet: function(d){
                            if (d.workOrderStatus == '2') {
                                return '<span style="color: #52C41A;">'+"已完成"+'</span>';
                            } else if (d.workOrderStatus == '1'){
                                return '<span style="color: #c7bb00;">'+"正在受理"+'</span>'
                            }else{
                                return '<span style="color: #c00;">'+"未回复"+'</span>'
                            }
                        }},
                {field: 'employeeNo', width: 120, title: '回复员工号'},
                    {field: 'employeeName', width: 120, title: '回复员工姓名'},
                {field: 'starLevel', width: 120, title: '评价等级', sort: true},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var user= layer.open({
                    type: 1,
                    area: ['100%', '100%'],
                    content: $("#user"),
                    success:function(data){
                        $('#customerId').html("");
                        $('#employeeNos').html("");
                        $.ajax({
                            url:"/admin/system/queryAllCustomer",
                            type:"get",
                            data:{
                            },
                            dataType:"json",
                            success:function(data){
                                for(var i = 0; i < data.length; i++){
                                    $('#customerId').append(new Option(data[i].userName,data[i].id));
                                }
                                form.render();
                            }
                        })

                        $.ajax({
                            url:"/admin/system/queryAllEmployees",
                            type:"get",
                            data:{
                            },
                            dataType:"json",
                            success:function(data){
                                for(var i = 0; i < data.length; i++){
                                    $('#employeeNos').append(new Option(data[i].employeeName,data[i].employeeNo));
                                }

                                form.render();
                            }
                        });
                    }
                });



                form.on('submit(saveBtn)', function (data) {
                    var a=new Date();
                    var c = a.toLocaleDateString();
                    var e = a.getHours();
                    var f =a.getMinutes();
                    var g= c+" "+e+":"+f;
                    $.ajax({
                        url:"/admin/system/addWorkOrders",
                        type:"get",
                        data:{
                            waybillNo:$('#waybillNo').val(),
                            cutomerName:$('#customerId').val(),
                            customerTel:0,
                            workOrderBeginTime:g,
                            questionType:$('#questionType').val(),
                            workOrderStatus:$('#workOrderStatus').val(),
                            employeeNo:$('#employeeNos').val(),
                            starLevel:$('#starLevel').val()
                        },
                        dataType:"text",
                        success:function(data){

                            table.reload('currentTableId', {
                                url:"/admin/system/queryAllWorkOrderEmployeeUseDto",
                                type:"get"
                            });

                            $('#waybillNo').val("");
                            $('#customerId').val("");
                            $('#questionType').val("");
                            $('#workOrderStatus').val("");
                            $('#employeeNos').val("");
                            $('#starLevel').val("");
                            layer.close(user);

                        }
                    })

                    return false;
                });

            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(employeeTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(employeeTableFilter)', function (obj) {
            var datas = obj.data;

            console.log(datas)

            if (obj.event === 'edit') {


                var pops= layer.open({
                    type: 1,
                    area: ['100%', '100%'],
                    content: $("#pop"),
                    success:function(data){

                        //面单号
                        $('#waybillNos').val(datas.waybillNo);

                        //工单状态
                        $('#questionTypes').val(datas.questionType);
                        //评价等级
                        $('#starLevels').val(datas.starLevel);
                        //问题类型
                        $('#workOrderStatuss').val(datas.workOrderStatus);
                        form.render();
                        $.ajax({
                            url:"/admin/system/queryAllCustomer",
                            type:"get",
                            data:{
                            },
                            dataType:"json",
                            success:function(data){
                                for(var i = 0; i < data.length; i++){
                                    $('#customerIds').append(new Option(data[i].userName,data[i].id));
                                }
                                $('#customerIds').val(datas.employeeId);
                                form.render();
                            }
                        });

                        $.ajax({
                            url:"/admin/system/queryAllEmployees",
                            type:"get",
                            data:{
                            },
                            dataType:"json",
                            success:function(data){


                                for(var i = 0; i < data.length; i++){
                                    $('#employeeNoss').append(new Option(data[i].employeeName,data[i].employeeNo));
                                }
                                $('#employeeNoss').val(datas.employeeNo);
                                form.render();
                            }
                        });


                    }


                });


                var aew =datas.workOrderId;
                form.on('submit(saveBtn)', function (data) {
                    $.ajax({
                        url:"/admin/system/updateWorkOrder",
                        type:"get",
                        data:{
                            workOrderId:aew,
                            waybillNo:$('#waybillNos').val(),
                            cutomerName:$('#customerIds').val(),
                            questionType:$('#questionTypes').val(),
                            workOrderStatus:$('#workOrderStatuss').val(),
                            employeeNo:$('#employeeNoss').val(),
                            starLevel:$('#starLevels').val()
                        },
                        dataType:"text",
                        success:function(data){
                            table.reload('currentTableId', {
                                url:"/admin/system/queryAllWorkOrderEmployeeUseDto",
                                type:"get"
                            });
                            layer.close(pops);
                        }
                    })

                    return false;
                });

            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {


                    $.ajax({
                        url:"/admin/system/deleteWorkOrder",
                        type:"get",
                        data:{
                            workOrderId:data.workOrderId
                        },
                        dataType:"text",
                        success:function(data){
                            table.reload('currentTableId', {
                                url:"/admin/system/queryAllWorkOrderEmployeeUseDto",
                                type:"post"
                            });

                        }
                    })

                    obj.del();
                    layer.close(index);
                });
            }
        });

    });
</script>


<div style="display:none" id="user">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">面单号</label>
            <div class="layui-input-block" style="width: 200px;">
                <input type="text" id="waybillNo"   value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" >客户名称</label>
            <div class="layui-input-inline" style="width: 200px;"  >
            <select name="customerId" lay-filter="test11" id="customerId" >

            </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">问题类型</label>
            <div class="layui-input-block" style="width: 200px">
                <textarea id="questionType" lay-verify="required" style="width: 775px;"placeholder="请输内容" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工单状态</label>
            <div class="layui-input-block" style="width: 200px">
                <select name="workOrderStatus" lay-filter="aihao" id="workOrderStatus" >
                    <option value="">选择工单状态</option>
                    <option value="0">未回复</option>
                    <option value="1">正在受理</option>
                    <option value="2">已完成</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">回复员工号</label>
            <div class="layui-input-block" style="width: 200px">
                <select name="employeeNo" lay-filter="test11" id="employeeNos" >
                </select>
                </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">评价等级</label>
            <div class="layui-input-block" style="width: 200px">
                <input type="text" id="starLevel"   value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>


<div style="display:none" id="pop">
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">面单号</label>
            <div class="layui-input-block" style="width: 200px;">
                <input type="text" id="waybillNos"   value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" >客户名称</label>
            <div class="layui-input-inline" style="width: 200px;"  >
                <select name="customerId" lay-filter="suea" id="customerIds" >
                    <option value="">选择客户名称</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">问题类型</label>
            <div class="layui-input-block" style="width: 200px">
                <textarea id="questionTypes" lay-verify="required" style="width: 775px;"placeholder="请输内容" autocomplete="off" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">工单状态</label>
            <div class="layui-input-block" style="width: 200px">
                <select name="workOrderStatus" lay-filter="aihao" id="workOrderStatuss" >
                    <option value="">选择工单状态</option>
                    <option value="0">未回复</option>
                    <option value="1">正在受理</option>
                    <option value="2">已完成</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">回复员工号</label>
            <div class="layui-input-block" style="width: 200px">
                <select name="employeeNo" lay-filter="aihao" id="employeeNoss" >
                    <option value="">选择员工名称</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">评价等级</label>
            <div class="layui-input-block" style="width: 200px">
                <input type="text" id="starLevels"   value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
